package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.PictureDao;
import ysq.xyg.model.Picture;
import ysq.xyg.service.PictureService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分类实现
 *
 * @author congcong tao
 * @date 2018/8/7 11:46
 */
@Service("pictureService")
public class PictureServiceImpl extends BaseServiceImpl<Picture> implements PictureService {

    @Resource
    private PictureDao pictureDao;
    @Autowired
    public void setpictureDao(PictureDao pictureDao) {
        this.baseDao = pictureDao;
    }

    @Override
    public PageInfo<Picture> pageInfo(Picture picture, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        // 通用Example查询
        Example example = new Example(Picture.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(picture.getIsShow())) {
            criteria.andEqualTo("isShow", picture.getIsShow());
        }
        example.orderBy("sortOrder asc");
        List<Picture> list = pictureDao.selectByExample(example);
        return new PageInfo<Picture>(list);
    }

    @Override
    public List<Picture> selectLimit(int pageStart, int pageEnd) {
        return pictureDao.selectLimit(pageStart, pageEnd);
    }
}
